<?php

Class Paginationhelp {

    public static function get_data($table,$field,$tiaojian = 'DESC') {

        $pagination = Pagination::factory(
                        array(
                            'current_page' => array('source' => 'query_string', 'key' => 'page'),
                            'total_items' => self::get_count($table),
                            'auto_hide' => 'FALSE',
                        )
        );


        $pagination_arr['pagination']= $pagination;
        
        $pagination_arr['data'] = ORM::factory($table)
                ->order_by($field, $tiaojian)
                ->limit($pagination->items_per_page)
                ->offset($pagination->offset)
                ->find_all()
                ->as_array();
        
        if(is_array($pagination_arr)) {
            return $pagination_arr;
        } else {
            return false;
        }
    }



    public static function get_count($table) {

        $count = ORM::factory($table)->count_all();

        return $count;
    }

}